<template>
    <div class="sortView">
        <van-tabs v-model:active="activeName" @click-tab="onClickTab" animated>
            <van-tab v-for="item in blogClassNameList" :title="item.article_class" :name="item.article_class"
                :key="item.id">
                <!-- 文章列表 -->
                <div @click="GoblogContent(item.content_id)" class="blogItem_box" v-for="item in classArticeList">
                    <div class="blogItem-imgbox">

                        <img v-lazy="item.cove_image ? item.cove_image : 'https://s1.ax1x.com/2023/04/03/ppfxklD.png'"
                            alt="">
                    </div>
                    <div class="blogItem-textbox">
                        <div class="article-title-class">
                            <!-- <p>{{ item.article_class }}</p> -->
                            <van-text-ellipsis rows=2 :content="item.title" />
                        </div>
                        <van-text-ellipsis class="blogItem-describe" rows=2 :content="item.article_describe" />
                        <div class="blogItem-botbox">
                            <p>{{ item.create_timer }}</p>
                            <span>{{ item.article_class }}</span>
                        </div>
                    </div>
                </div>
                <!-- 数据空的时候显示没有啦 -->
                <!-- <div v-if="!blogItemArr.length">
                </div> -->
                <!-- 结束 -->
            </van-tab>
        </van-tabs>
    </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { getblogclass, selectclass } from "@/api/request";
import { storeToRefs } from "pinia";
import { useStore } from "@/store";
// 路由跳转
import { useRouter } from "vue-router";
const router = useRouter();

const store = useStore();
let { } = storeToRefs(store);

const activeName = ref('默认分类');
const blogClassNameList = ref([])

onMounted(() => {
    // 请求所有分类
    getblogclass().then(({ data }) => {
        // console.log(data);
        blogClassNameList.value = data.data
    })
    onClickTab()
})
const classArticeList = ref([])
// 点击渲染不同文章
const onClickTab = () => {
    // console.log(activeName.value);
    selectclass({
        className: activeName.value
    }).then(({ data }) => {
        classArticeList.value = data.data
        // console.log(classArticeList.value);

    })
}
// 路由跳转
// 跳转到内容
const GoblogContent = (id) => {
    router.push({
        path: "/blogContent",
        query: {
            blogItemID: id,
        }
    })
}
</script>

<style lang="scss">
.sortView {
    padding: 3.125rem 0 .625rem;
    min-height: 36.25rem;

    // 每一个文章的样式
    .blogItem_box {
        padding: 14px 10px;
        margin: 14px 0;
        border-radius: 6px;
        box-sizing: border-box;
        display: flex;
        // box-shadow: var(--boxshadow);
        background-color: white;

        .blogItem-imgbox {
            img {
                width: 6.25rem;
                height: 6.25rem;
                border-radius: 12px;
            }
        }


        .blogItem-textbox {
            width: 100%;
            margin-left: 10px;
            position: relative;

            >.article-title-class {

                .van-text-ellipsis {
                    font-size: 15px;
                    font-weight: bold;
                    line-height: 20px;
                }

            }

            // 描述
            .blogItem-describe {
                // margin: 4px 0;
                font-size: 13px;
                color: #aaa;
                margin: 0px 0 20px;
            }

            // 最底部
            .blogItem-botbox {
                width: 100%;
                position: absolute;
                bottom: 0;
                margin: 0;
                display: flex;
                align-items: center;

                p {
                    font-size: 12px;
                    margin: 0;
                }

                span {
                    font-size: 12px;
                    color: #fff;
                    background-color: var(--motifColor);
                    padding: 2px 4px;
                    border-radius: 6px;
                    position: absolute;
                    top: 0;
                    right: 0;
                }
            }
        }

    }
}
</style>